package com.structure.algorithm;

/**
 * 字符串操作
 * Created by sucre on 2015/11/9.
 */
public class StringOperation {
    //利用倒排序法进行字符替换
    public static String replaceString(String m) {
        if (m == null || m == "") {
            return "-1";
        }
        char[] s = m.toCharArray();
        //这里也用到了双指针
        int j = s.length - 1;
        for (int i = s.length - 1; i >= 0; i--) {
            if (Character.isDigit(s[i])) {
                s[j--] = s[i];
            }
        }
        //由于i走的比j要快，所以j少走的几步即为*号
        for (; j >= 0; --j) {
            s[j] = '*';
        }
        return String.valueOf(s);
    }
    public static void main(String[] args){
        System.out.print(replaceString("**56*87"));
    }
}
